package com.Bigbluebook.Service;

import com.Bigbluebook.api.ApiConstants;
import com.Bigbluebook.entity.Comment;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.Path;

public class CommentApiService {
    private CommentService commentService;
    private Retrofit retrofit;
    private Gson gson;

    public CommentApiService(){
        gson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
                .create();
        retrofit = new Retrofit.Builder()
                .baseUrl(ApiConstants.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
        commentService = retrofit.create(CommentService.class);
    }

    public void createComment(Comment comment, Callback<Comment> callback) {
        Call<Comment> call = commentService.createComment(comment);
        call.enqueue(callback);
    }

    public void getComment(int commentId, Callback<Comment> callback) {
        Call<Comment> call = commentService.getComment(commentId);
        call.enqueue(callback);
    }

    public void getAllCommentsForPost(int postId, Callback<List<Comment>> callback) {
        Call<List<Comment>> call = commentService.getAllCommentsForPost(postId);
        call.enqueue(callback);
    }

    public void updateComment(int commentId, Comment comment, Callback<Comment> callback) {
        Call<Comment> call = commentService.updateComment(commentId, comment);
        call.enqueue(callback);
    }

    public void deleteComment(int commentId, Callback<Void> callback) {
        Call<Void> call = commentService.deleteComment(commentId);
        call.enqueue(callback);
    }

    public void getAllCommentsByUser(int userId,Callback<List<Comment>> callback){
        Call<List<Comment>> call = commentService.getAllCommentsByUser(userId);
        call.enqueue(callback);
    }
}
